package com.ruoyi.central.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.cache.common.CacheConstants;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.service.ServiceImpl;
import com.ruoyi.central.mapper.TopCentralOperationStationMaterialLogMapper;
import com.ruoyi.central.domain.TopCentralOperationStationMaterialLog;
import com.ruoyi.central.service.ITopCentralOperationStationMaterialLogService;
import com.ruoyi.common.utils.StringUtils;

/**
 * 任务执行指令Service业务层处理
 *
 * @author SunLuQuan
 * @date 2022-06-29
 */
@Service
@Slf4j
@CacheConfig(cacheNames = CacheConstants.EhcacheName.CONTINUAL_CACHE_NAME)
public class TopCentralOperationStationMaterialLogServiceImpl extends ServiceImpl<TopCentralOperationStationMaterialLogMapper,TopCentralOperationStationMaterialLog> implements ITopCentralOperationStationMaterialLogService
{
    /**
     * 查询任务执行指令
     * 
     * @param id 任务执行指令主键
     * @param columns 查询指定的列
     * @return 任务执行指令
     */
    @Override
    public TopCentralOperationStationMaterialLog selectById(Integer id, SFunction<TopCentralOperationStationMaterialLog,?> ... columns){

        if(StringUtils.isNotEmpty(columns)){
            return selectOne(lambdaQuery().select(columns).eq(TopCentralOperationStationMaterialLog::getId,id));
        }
        return super.selectById(id);
    }

    /**
     * 查询任务执行指令列表
     *
     * @param topCentralOperationStationMaterialLog 任务执行指令
     * @return 任务执行指令
     */
    @Override
    public List<TopCentralOperationStationMaterialLog> selectList(TopCentralOperationStationMaterialLog topCentralOperationStationMaterialLog)
    {
        return getBaseMapper().selectTopCentralOperationStationMaterialLogList(topCentralOperationStationMaterialLog);
    }

    /**
     * 获取所有的任务执行指令数据
     * 
     * @return Map<Integer,TopCentralOperationStationMaterialLog> 集合
     */
    @Cacheable
    @Override
    public Map<Integer,TopCentralOperationStationMaterialLog> selectAllMap(){

        return getBaseMapper().selectList( lambdaQuery())
                .stream().collect(Collectors.toMap(TopCentralOperationStationMaterialLog::getId,v->v));
    }

    /**
     * 新增任务执行指令
     *
     * @param topCentralOperationStationMaterialLog 任务执行指令
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insert(TopCentralOperationStationMaterialLog topCentralOperationStationMaterialLog)
    {
        return super.insert(topCentralOperationStationMaterialLog);
    }

    /**
     * 新增（批量）任务执行指令
     *
     * @param topCentralOperationStationMaterialLogList 实体对象集合
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean insertBatch(Collection<TopCentralOperationStationMaterialLog> topCentralOperationStationMaterialLogList, int batchSize) {
        return super.insertBatch(topCentralOperationStationMaterialLogList, batchSize);
    }

    /**
     * 删除 任务执行指令 根据编号
     * @param id
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }

    /**
     * 批量删除 任务执行指令 根据 编号集合
     * @param ids
     * @return true 删除成功 false 删除失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean deleteByIds(Collection<? extends Serializable> ids) {
        return super.deleteByIds(ids);
    }

    /**
     * 批量修改 任务执行指令 根据唯一编号
     * @param topCentralOperationStationMaterialLogList
     * @param batchSize  更新批次数量
     * @return true 修改成功 false 修改失败
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateBatchById(Collection<TopCentralOperationStationMaterialLog> topCentralOperationStationMaterialLogList, int batchSize) {
        return super.updateBatchById(topCentralOperationStationMaterialLogList, batchSize);
    }

    /**
     * 修改 任务执行指令
     * @param  topCentralOperationStationMaterialLog
     * @param updateWrapper
     * @return
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean update(TopCentralOperationStationMaterialLog topCentralOperationStationMaterialLog, LambdaUpdateWrapper<TopCentralOperationStationMaterialLog> updateWrapper) {
        return super.update(topCentralOperationStationMaterialLog,updateWrapper);
    }

    /**
     * 修改任务执行指令
     *
     * @param topCentralOperationStationMaterialLog 任务执行指令
     * @return 结果
     */
    @CacheEvict(keyGenerator=CacheConstants.KeyGeneratorName.EHCACHE_KEY_GENERATOR_EVICT)
    @Override
    public boolean updateById(TopCentralOperationStationMaterialLog topCentralOperationStationMaterialLog)
    {
        return super.updateById(topCentralOperationStationMaterialLog);
    }


}
